<template>
	<view class="Index">
		<view class="nav-back">
			<u-navbar leftText="歌单广场" :autoBack="true" leftIcon="arrow-leftward">
			</u-navbar>
		</view>
		<!-- 瀑布流布局列表 -->
		<view class="pubuBox">
			<view class="pubuItem">
				<view class="item-masonry" v-for="(item, index) in comList" :key="index" @click="send(item.id)">
					<image :src="item.picUrl" mode="widthFix"></image>
					<view class="listtitle">
						<view class="listtitle1">{{ item.name}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="loadmore">
			<u-loadmore bg-color="rgb(240, 240, 240)" nomore-text="没有更多了" :status="loadStatus" @loadmore="SongsSheet">
			</u-loadmore>
		</view>

	</view>
</template>

<script>
	import {
		getRecSongsSheet
	} from '@/http/home.js'
	export default {
		data() {
			return {
				comList: [], //商品列表
				limit: 20, //数据的获取的数量
				length: 0,
				loadStatus: 'loadmore',
			};
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				this.SongsSheet();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		methods: {
			async SongsSheet() {
				this.limit = this.limit + 20 // 搜索的数据 ++ 
				this.length = this.length + 20 // 删除前面搜索的 数据
				const res = await getRecSongsSheet(this.limit);
				const data = res.result.splice(0, this.length);
				this.comList = [...this.comList, ...res.result] //老数据，拼接新数据 
			},
			// 歌单详情
			send(id) {
				uni.navigateTo({
					url: '/view/SongSheet/SongSheet?id=' + id
				})
			},
		},
		created() {
			this.SongsSheet()
		}

	};
</script>

<style scoped="scoped" lang="scss">
	.nav-back {
		height: 85rpx;
	}

	//瀑布流
	page {
		background-color: #eee;
		height: 100%;
	}

	.pubuBox {
		padding: 22rpx;
	}

	.pubuItem {
		column-count: 2;
		column-gap: 20rpx;
	
	}

	.item-masonry {
		box-sizing: border-box;
		border-radius: 15rpx;
		overflow: hidden;
		background-color: #fff;
		break-inside: avoid;
		/*避免在元素内部插入分页符*/
		box-sizing: border-box;
		margin-bottom: 20rpx;
		box-shadow: 0px 0px 28rpx 1rpx rgba(78, 101, 153, 0.14);
	}

	.item-masonry image {
		width: 100%;
	}

	.listtitle {
		padding-left: 22rpx;
		font-size: 24rpx;
		padding-bottom: 22rpx;

		.listtitle1 {
			line-height: 39rpx;
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			line-clamp: 2;
			-webkit-box-orient: vertical;
			min-height: 39rpx;
			max-height: 78rpx;
		}

		.listtitle2 {
			color: #ff0000;
			font-size: 32rpx;
			line-height: 32rpx;
			font-weight: bold;
			padding-top: 22rpx;

			.listtitle2son {
				font-size: 32rpx;
			}
		}

		.listtitle3 {
			font-size: 28rpx;
			color: #909399;
			line-height: 32rpx;
			padding-top: 22rpx;
		}
	}

	.Index {
		width: 100%;
		height: 100%;
	}

	.loadmore {
		height: 45rpx;
	}
</style>
